﻿import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3

import "../../js/UI.js" as Style
import "../../js/util.js" as Util
Rectangle {
    id: root
    property alias m_placeholderText: content.placeholderText
    property alias m_text: content.text
    property alias m_inputMethodHints: content.inputMethodHints
    property alias m_validator: content.validator
    property alias m_focus: content.focus
    property alias imagesoure: iamgeID.source
    property alias a_clearBtn: iamgeID
    property bool p_btnClearVisible:true
    property alias m_textColor: content.textColor
    property alias content_readonly: content.readOnly
    property alias m_inputarea: content
    property alias m_splitLine: m_splitLine
    property var  m_palceTextColor: Style.textPlaceHoldColor
    property int m_size: 18

    // @hebangning add
    property alias m_mouseSelect: content.selectByMouse;

    property var leftMargin: 0
    signal deleteSignal(int index);
    color: "#fafafa"

    TextField {
        id: content
        anchors.left: parent.left
        anchors.leftMargin:leftMargin
        anchors.verticalCenter: parent.verticalCenter
        width: btnClear.visible ? parent.width - btnClear.width : parent.width
        height: parent.height
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignLeft
        style: style
        maximumLength: 11
        font.pointSize: m_size
        font.family: Style.fontfamily
        selectByMouse: true
        onTextChanged: {
            if(!p_btnClearVisible){
                return
            }
            if (text.length > 0) {
                btnClear.visible = true
            } else {
                btnClear.visible = false
            }
        }

        onCursorPositionChanged: {
            if (!Util.isMobileDevice()) { return; }
            if (selectedText.length > 0) {
                deselect()
            }
        }
    }

    SplitLine {
        id:m_splitLine
        width: parent.width
        anchors.bottom: parent.bottom
    }

    Item {
        id: btnClear
        width: parent.height
        height: width
        anchors.right: parent.right
        anchors.rightMargin: m_lineValue*0.1
        visible: false

        Image {
            id: iamgeID
            width: m_lineValue*0.4
            height: width
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/images/icon_quxiao.png"
        }

        MouseArea {
            anchors.fill: parent
            enabled: p_btnClearVisible
            onClicked: {
                content.text = ""
                deleteSignal(index);
            }
        }
    }

    Component {
        id: style
        TextFieldStyle
        {
            placeholderTextColor: content.focus?m_palceTextColor:Style.lineColorcall
            textColor: Style.fonttilteColor
            font{family:Style.fontfamily}
            background: Item {}
        }
    }
}

